﻿using System;
using System.IO;

namespace AvaloniaMvvm.Helpers;
/**
 * 当一个类 被static修饰时 就不会被牛
 */
public static class PathHelper
{
    private static string _localFolder = string.Empty;
    
    // 懒加载 lazy
    private static string LocalFolder
    {
        get
        {
            if (string.IsNullOrEmpty(_localFolder))
            {
                return _localFolder;
            }
            _localFolder = 
                Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.
                        LocalApplicationData), nameof(AvaloniaMvvm)
            );
            // 确保路径一定存在
            if (!Directory.Exists(_localFolder))
            {
                Directory.CreateDirectory(_localFolder);
            }
            return _localFolder;
        }
        
    }

    // 获取文件路径方法
    public static string GetLocalFilePath(string fileName)
    {
        return Path.Combine(LocalFolder, fileName);
    }
}